package com.tongtong.stsuserapi.controller;

import com.tongtong.stscommon.message.STSMessage;
import com.tongtong.stscommon.proxy.annotation.AutoGetId;
import com.tongtong.stsuserapi.service.base.ClassificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类控制器
 */
@Api(tags="分类接口")
@RestController
@RequestMapping("/sts/manager/classification")
public class ClassificationController {

	@Autowired
	ClassificationService classificationService;

	@ApiOperation(value="获取分类列表")
	@GetMapping
	STSMessage getClassificationList(Integer page, Integer pageSize) {
		return classificationService.getClassificationList(page,pageSize);
	}

	@ApiOperation(value="添加一个商品分类")
	@ApiImplicitParam(name = "managerId", value = "该参数从token中自动获取，无需传入")
	@PostMapping
	@AutoGetId
	STSMessage addClassification(Long managerId, String classificationName) {
		return classificationService.addClassification(managerId, classificationName);
	}

	@ApiOperation("修改一个商品分类")
	@ApiImplicitParam(name = "managerId", value = "该参数从token中自动获取，无需传入")
	@PatchMapping
	@AutoGetId
	STSMessage alterClassification(Long managerId, Long classificationId, String classificationName) {
		return classificationService.alterClassification(managerId,classificationId,classificationName);
	}

	@ApiOperation("批量删除商品分类")
	@DeleteMapping
	STSMessage deleteClassification(List<Long> classificationIds) {
		return classificationService.deleteClassificationByList(classificationIds);
	}

}
